from common import *

import pylab

default_data = None

def setup(data = default_data):
    import wx
    import os
    wildcard = "PNG (*.png)|*.png|"     \
               "All files (*.*)|*.*"

    saveDir = os.getcwd()

    dlg = wx.FileDialog(
        None, message="Choose an image file, containing the data",
        defaultDir=os.getcwd(),
        defaultFile="",
        wildcard=wildcard,
        style=wx.OPEN | wx.CHANGE_DIR
        )

    if dlg.ShowModal() == wx.ID_OK:
        # This returns a Python list of files that were selected.
        paths = dlg.GetPaths()
        data = paths[0].replace(saveDir + '/', '')

    os.chdir(saveDir)
    dlg.Destroy()
    return data

def ReadImageFileFunc(out0 , data = default_data):    

    img = pylab.imread(str(data))

    # Convert to grayscale
    img = pylab.sum(img,img.ndim - 1);

    out0(img)
